class Solution {
    public int removeElement(int[] nums, int val) {
        int len = nums.length;
        if(0 == len) {
            return 0;
        }
        int i = 0;
        int j = 0;
        
        while(j<len) {
            while(j<len && val == nums[j]) {
                j++;
            }
            
            if(i != j && j<len) {
                nums[i] = nums[j];
            } 
            if(j >= len) {
                break;
            }
            i++;
            j++;
        }
        return i;
    }
}